package enumdemo;

import reflectdemo.Test;

/**
 * @Author 12629
 * @Description：
 */
public enum TestEnum {
    RED("red",2),BLACK("BLACK",3),
    GREEN("GREEN",4),WHITE("WHITE",5);
    public String color;
    public int ordinal;
     TestEnum(String color,int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main(String[] args) {
        //拿到枚举实例BLACK
        TestEnum testEnum = TestEnum.BLACK;
        //拿到枚举实例RED
        TestEnum testEnum21 = TestEnum.RED;
        System.out.println(testEnum.compareTo(testEnum21));
        System.out.println(BLACK.compareTo(RED));
        System.out.println(RED.compareTo(BLACK));
    }

    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i]+" 序号："+testEnums[i].ordinal());
        }

        System.out.println("============");
        TestEnum testEnum = TestEnum.valueOf("GREEN");
        System.out.println(testEnum);



    }

    public static void main1(String[] args) {
        TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHITE:
                System.out.println("WHITE");
                break;
            case GREEN:
                System.out.println("green");
                break;
            default:
                break;
        }
    }
}
